﻿using System;

namespace AgFractal.Fractals
{
    public class NovaMandelbrot : AbstractFractal
    {

        public NovaMandelbrot()
        {
            Name = Description = "Nova mandelbrot";
            ID = new Guid("54D3B0E7-A246-478b-B040-D13C4312A514");
            R1 = -2.25; I1 = 2; R2 = 3.75; I2 = -2;
        }

        protected override short Calculate(double r, double i, short MaxIteration)
        {
            short j;
            Complex z = new Complex(1, 0);
            Complex z2, z3, t;
            Complex start = new Complex(r, i);
            for (j = 0; j < MaxIteration; j++)
            {
                z2 = z * z;
                z3 = z2 * z;
                t = z;
                z = z - (z3 - 1) / (3 * z2) + start;
                if ((z - t).Abs2() < 1e-10) break;
            }
            return j;
        }
    }
}